import {getBaseCategoryList,getMockList,getFloors} from 'api/api';
export default{
    state:{
        categoryList:[],
        banners:[],
        floors:[]
    },
    mutations:{
        getCategoryList(state,categoryList){
            state.categoryList=categoryList
        },
        getMockList(state,banners){
            state.banners=banners
        },
        getFloors(state,floors){
            state.floors=floors
        }
    },
    actions:{
        async getCategoryList(store){
            try{
               const {code,data}= await getBaseCategoryList()
            //    console.log(data);
                if(code===200){
                    store.commit('getCategoryList',data)
                }else{

                }
               return {code,data}
            }catch(e){
                return Promise.reject(e)
            }
        },
        async getMockList(store){
            try{
               const {code,data}= await getMockList()
            //    console.log(data);
                if(code===200){
                    store.commit('getMockList',data)
                }else{

                }
               return {code,data}
            }catch(e){
                return Promise.reject(e)
            }
        },
        async getFloors(store){
            try{
               const {code,data}= await getFloors()
            //    console.log(data);
                if(code===200){
                    store.commit('getFloors',data)
                }else{

                }
               return {code,data}
            }catch(e){
                return Promise.reject(e)
            }
        }
    },
    getters:{
        switchFloors(state){
            let floors=state.floors;
            floors.forEach(floor=> {
                if(floor.carouselList){
                    floor.carouselList=floor.carouselList.map(({id,imgUrl})=>({
                        id,
                        url:imgUrl
                    }))
                }
            });
            return floors
        }
    }
}